package com.dsp.week05starter.conf;

import com.dsp.week05starter.service.DemoService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author dsp
 * @date 2021-04-18
 */
@Configuration
@EnableConfigurationProperties(DemoProperties.class)
@ConditionalOnProperty(prefix = "demo", name = "enable", havingValue = "true")
public class DemoAutoConfig {

     @Resource
     private DemoProperties demoProperties;

     @Bean(name = "demoService")
     public DemoService demoService(){
         return new DemoService(demoProperties.getSay(), demoProperties.getWho());
     }
}
